﻿#include "dxstdafx.h"
#include "CStrategyLogicMap.h"
#include "Strategy/Scene/CStrategyRenderCommon.h"
#include "Data/DataMgr.h"
#include "Data/ProgramData/ProgramDataMgr.h"
#include "Data/ProgramData/ProvinceData.h"
#include "Strategy/CStrategyDefine.h"
#include "Support/GUI/DialogManager.h"
#include "Strategy/GUI/ProvinceInterface/GuiProvince.h"

bool CStrategyLogicMap::OnLClickMap(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	POINT ptCursor = { (short)LOWORD(lParam), (short)HIWORD(lParam) };
	D3DXVECTOR2 ptVec = CommonFunc::Cursor2CameraSpace(ptCursor);
	CPoint ptOut;
	CStrategyRenderFunc::GetTerrainXYByScreenPos(ptVec.x, ptVec.y, ptOut);
	
	wprintf_s(L"Click Point(%d, %d)\n", ptOut.x, ptOut.y);
	
	int TerrainIndex = CMathFunc::XYTran2Index(ptOut.x, ptOut.y, c_nTerrainWidth, c_nTerrainHeight);
	const _stProvinceInfo* const* pEPP = CDataMgr::Singleton().GetProgramDataMgrCPtr()->GetProvinceDataCPtr()->GetEachPointProvincePointer();
	if (pEPP[TerrainIndex] && pEPP[TerrainIndex]->IsCountyPalatine())
	{
		OnSelectProvince(const_cast<_stProvinceInfo*>(pEPP[TerrainIndex]));		// 需要修改值
	}
	return false;
}

void CStrategyLogicMap::OnSelectProvince(_stProvinceInfo* pProvinceSelect)
{
	if (nullptr == pProvinceSelect || !pProvinceSelect->IsCountyPalatine())
	{
		return;
	}
	if (m_pProvinceSelect && m_pProvinceSelect->IsCountyPalatine() && m_pProvinceSelect->IsSelect())
	{
		m_pProvinceSelect->SetSelect(false);
	}
	m_pProvinceSelect = pProvinceSelect;
	m_pProvinceSelect->SetSelect(true);
	wprintf_s(L"Province %s Is Selected\n", m_pProvinceSelect->IndexName.c_str());

	GuiProvince* pGuiProvince = static_cast<GuiProvince*>(DialogManager::Singleten().GetDialog(L"StrategyProvince00"));
	if (pGuiProvince)
	{
		pGuiProvince->SetChooseProvincePtr(m_pProvinceSelect);
	}
}

void CStrategyLogicMap::OnCancleSelectProvince()
{

}
